ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SCAN a variable for a specific character and split in two different variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SCAN a variable for a specific character and split in two different variables

    Hi guys, can you help me with some tips concerning the scan in CLLE and substring the variable and split it in two diferent variables?
    I have something like this - I want to create in IFS a path with some value received in parameters:
    PGM PARM( &DIR)

    I want to create the directories unde /home

    I have MKDIR (&PATH) where &PATH='/home' *TCAT &DIR
    but I have some cases when &DIR it's not an atomic value such My_directory, in some cases I have My_dir/My_subdir

    and in this cases the MKDIR fails because I saw that I have to create initially the parent directory, in this case /home/My_dir, to be able to create /home/My_dir/My_subdir
    How can I scan the &DIR to see if I have some '/' slashes into the string and split it in different variables and build the path step by step and create each directory into IFS?


  • #2
    STRQSH CMD('mkdir -p ''/home/My_dir/My_subdir'' ')

    When the -p option is specified, mkdir creates all of the directories in the path.

    Ringer

    Comment


    • #3
      Thank you!

      Comment


      • #4
        one more question, if the subidrectory already exists how can I handle this? because I have error message in the QSH interface not in the CL program?
        I want to create automatically the directories in the IFS for several programs who should run daily and I want to put this command inside the programs and at the first run the paths must be build and further on when one program by example is launched in the second day, so, it will be the second run, the path already exist, to monitor the error and go on to the rest of the treatment.

        Comment


        • #5
          Sorry, I only gave you a partial solution. You can prevent the QSHELL output and also trap for errors in CL.

          Code:
          /* Error handling */                      
          DCL  VAR(&MsgID     ) TYPE(*CHAR) LEN(7)  
          DCL  Var(&MsgDta4   ) Type(*CHAR) Len(4)  
          DCL  Var(&RtnCode   ) Type(*DEC ) Len(10 0) 
          
          AddEnvVar EnvVar(QIBM_QSH_CMD_OUTPUT) +     
                       Value('NONE') Replace(*YES)
          AddEnvVar EnvVar(QIBM_QSH_CMD_ESCAPE_MSG) + 
                       Value('Y' ) Replace(*YES)
          STRQSH CMD(&QshCmd) /* whatever */ 
          
          /* QSHELL ERROR TRAPPING INFO ------------------------- */
          /* MsgF = QZSHMSGF. &1 is *BIN 4. *BIN values 0 to 255  */
          /* QSH0005: Command ended normally with exit status &1. */
          /* QSH0006: Command was ended by signal number &1.      */
          /* Command ended normally with exit status 1.           */
          /* > Message type: Escape                               */
          /* Command ended normally with exit status 0.           */
          /* > Message type: Completion                           */
          /* QSH0007: Command was ended by an exception.          */
          
          MONMSG MSGID(QSH0005 QSH0006) EXEC(DO)                          
             RCVMSG MSGTYPE(*EXCP) RMV(*NO) MSGID(&MsgID) MSGDTA(&MsgDta4)
             CHGVAR VAR(&RTNCODE) VALUE(%BIN(&MSGDTA4))                   
             If Cond(&RtnCode *GT 0) Then(Do) 
          /* some error */ 
             EndDo                                                        
          EndDo                                                           
          
          MONMSG MSGID(QSH0007) EXEC(DO)                                  
          /* some error */ 
          EndDo                                      
          
          RMVENVVAR ENVVAR(QIBM_QSH_CMD_OUTPUT) 
          MONMSG MSGID(CPFA981) 
          RMVENVVAR ENVVAR(QIBM_QSH_CMD_ESCAPE_MSG) 
          MONMSG MSGID(CPFA981)
          Ringer

          Comment


          • #6
            Thank you Ringer!

            Comment

            Working...
            X