Calling command line program from custom COBOL program

 12 Replies
 0 Subscribed to this topic
 17 Subscribed to this forum
Sort:
Author
Messages
John Costa
Veteran Member
Posts: 154
Veteran Member

    I've written a custom COBOL batch program (named P1006) that I want to use to call a SQL-Server package from the operating system command line.  The command string I'm generating within the P1006 uses two parameters entered into the program by the user.   The COBOL program compiles correctly and executes.  However, the command string being executed is not the command string that the program is generating. 

    I put in a display so that it echoes the command to an output file and I've verified the command syntax is correct.  I've gone as far as copying the command to my Windows clipboard, pasting it into a DOS prompt, and executing it without error.

    The problem is that when the command is actually executed by COBOL, it's putting my two parameters plus a "N" character in front of the command string.  The command string then fails. 

    I'd be more than happy to provide the program files here for review if someone thinks they can help.  I sure could use some.

    _________________ John - Wichita, KS
    Sam Simpson
    Veteran Member
    Posts: 239
    Veteran Member
      Can you just provide the statement that creates the command string and call. Usually what I do is call a script (ksh etc) that has the command and you can pass parameters to it.
      John Costa
      Veteran Member
      Posts: 154
      Veteran Member

        Attached is the output file from my P1006 program.  You'll be able to see the command string I'm trying to execute (following the "USING COMMAND STRING OF" entry) and the actual command that is executed (beginning with the word "Option").

        Since the "Option" entry is occurring below the Microsoft copyright notice, I'm wondering if it's actually SQL-Server throwing the error and not my COBOL program.  But this doesn't make sense since the displayed command above the Microsoft notice will execute correctly.

        Attachments
        _________________ John - Wichita, KS
        John Costa
        Veteran Member
        Posts: 154
        Veteran Member
          Hmmm, taking a look at the output file, I notice at the end of the command string, there's some text referencing the .prt file that is output by the P1006 program. I wonder if this file reference is somehow being passed as part of the command string, whcih in turn results in it's failure?
          _________________ John - Wichita, KS
          Ragu Raghavan
          Veteran Member
          Posts: 476
          Veteran Member
            I am curious to see how you built the command string - if you could post the WS and PD sections that pertian to this ...maybe I can spot something.
            John Costa
            Veteran Member
            Posts: 154
            Veteran Member

              Thanks for any help you can provide.  I'm driving myself crazy trying to figure this out.  Funny thing is, this program worked fine in my Lawson 8.x environment.  It's only since migrating it to LSF9 that it blows up.

              Attachments
              _________________ John - Wichita, KS
              John Costa
              Veteran Member
              Posts: 154
              Veteran Member

                Here's the text of the PD file:

                000100******************************************************************
                000200 050-EDIT-PARAMETERS             SECTION 10.
                000300******************************************************************
                000400 050-START.
                000500
                000600     IF (PRM-COMPANY-IN = ZEROES)
                001400         MOVE 050                   TO CRT-ERROR-NBR
                001500         MOVE WS-TRUE               TO WS-PARAMETER-ERROR
                001600         PERFORM 780-PRINT-ERROR-MSG
                001700         GO TO 050-END.

                000600     IF (PRM-MTH-END-DATE = ZEROES)
                001400         MOVE 052                      TO CRT-ERROR-NBR
                001500         MOVE WS-TRUE                  TO WS-PARAMETER-ERROR
                001600         PERFORM 780-PRINT-ERROR-MSG
                001700         GO TO 050-END.
                001800
                001900 050-END.
                002000
                002100******************************************************************
                002200 100-PROGRAM-CONTROL             SECTION 10.
                002300******************************************************************
                002400 100-START.
                002500
                002600     MOVE 051                    TO CRT-MSG-NBR.
                002700     PERFORM 780-DISPLAY-MSG.
                002800
                003100     PERFORM 1000-FIRE-OFF-DTS.
                003400
                003500 100-END.
                003600
                003700******************************************************************
                003800 1000-FIRE-OFF-DTS                 SECTION 50.
                003900******************************************************************
                004000 1000-START.
                            MOVE PRM-COMPANY-IN   TO WS-COMPANY-IN.
                004100      MOVE PRM-MTH-END-DATE   TO WS-MTH-END-DATE.
                            DISPLAY " ".
                               STRING "dtexec /FILE "
                                    WS-QUOTE
                                    "
                \\wchlawapp01\f$\DTSX_packages\"
                                    "Test_SSIS_package.dtsx"
                                    WS-QUOTE
                                    " /SET "
                                    WS-QUOTE
                                    "\Package.Variables[User::COMPANY]"
                                    ".Properties[Value]"
                                    WS-QUOTE
                                    ";"
                                    WS-COMPANY-IN
                                    " /SET "
                                    WS-QUOTE
                                    "\Package.Variables[User::MONTH_END_DATE]"
                                    ".Properties[Value]"
                                    WS-QUOTE
                                    ";"
                                    WS-MTH-END-DATE                  
                                    WS-CARRIAGE-RETURN
                                    DELIMITED BY SIZE INTO WS-DTS-COMMAND.
                            MOVE WS-DTS-COMMAND TO WS-DTS-COMMAND-DISP.
                            DISPLAY "USING COMMAND STRING OF:".
                            DISPLAY " ".
                            DISPLAY WS-DTS-COMMAND-DISP.
                            DISPLAY " ".
                006100      CALL "SYSTEM" USING WS-DTS-COMMAND.
                020000
                020100******************************************************************
                020200 1000-END.
                020300******************************************************************
                020400

                And here is the text of the WS file:

                000100******************************************************************
                000200*                            P1006WS                             *
                000300******************************************************************
                000400 01  P1006WS.
                002800    02 WS-DTS-COMMAND        PIC X(300) VALUE SPACES.
                          02 WS-COMPANY-IN         PIC X(2)   VALUE SPACES.
                          02 WS-MTH-END-DATE       PIC X(8)   VALUE SPACES.
                          02 WS-QUOTE              PIC X      VALUE X"22".
                          02 WS-CARRIAGE-RETURN    PIC X      VALUE X"0D".
                          02 WS-PROG-RNGPRM-SETTO-HV PIC X    VALUE "N".
                          02 WS-DTS-COMMAND-DISP   PIC X(300) VALUE SPACES.

                 

                _________________ John - Wichita, KS
                John Costa
                Veteran Member
                Posts: 154
                Veteran Member
                  Researching this further, it appears the error might have something to do with Net Express 5.
                  _________________ John - Wichita, KS
                  Sam Simpson
                  Veteran Member
                  Posts: 239
                  Veteran Member
                    Try putting a null character at the end of WS-DTS-COMMAND. The null character is x'00'.
                    John Costa
                    Veteran Member
                    Posts: 154
                    Veteran Member

                      Sam - I did see references to adding a null character to a command, but I couldn't find any examples of how to do that.

                      _________________ John - Wichita, KS
                      John Henley
                      Posts: 3353

                        When you pass a command string to the SYSTEM function, it needs to a null-terminated string wrapped in quotes, so here are a couple of suggestions:
                        1. Change your command string terminator to a null, not a carriage return.
                        2. You may need to experiment a little with the quotes, and you may find that it's easier to pass the variables to a script, and have the script call dtexec.

                        You can see an example of calling the SYSTEM function here:

                        Calling Operating System Commands from COBOL

                         

                        Thanks for using the LawsonGuru.com forums!
                        John
                        John Costa
                        Veteran Member
                        Posts: 154
                        Veteran Member
                          John - You saved me from pulling out the last bit of hair I had left. Changing the carriage return character in my WS file to a null character resolved the problem and my program executes correctly!

                          Have a beer on me. Make that several.

                          Thanks everyone for your help.
                          _________________ John - Wichita, KS
                          John Henley
                          Posts: 3353
                            Well, as someone with, um, "prematurely grey" hair, you're welcome!
                            Thanks for using the LawsonGuru.com forums!
                            John