Page 1 of 1

Cobol - how to delete spaces at starting postion in di

PostPosted: Tue Jul 13, 2010 3:16 pm
by kavalisubbarao
Hi ,

I have one question regarding elemination of spaces in cobol data item.

I have one data item,can you please tell me how to eliminate saomes spaces in starting of the string,

Re: Cobol - how to delete spaces at starting postion in di

PostPosted: Tue Jul 13, 2010 4:00 pm
by Robert Sample
Unlike C and similar languages, COBOL variables are fixed length (except when ODO is used). So when you say you want to eliminate spaces at the start of the variable (not string -- COBOL does not have strings), what do you mean? You could mean:
1. you want the data shifted left so the first bye is not a space
2. you want to replace the spaces with some other character (such as LOW-VALUE)
but if the variable is 60 bytes, you will have 60 bytes in that variable -- spaces, LOW-VALUES, printable characters, non-printing characters, but something will be in every one of those 60 bytes.

Re: Cobol - how to delete spaces at starting postion in di

PostPosted: Sun Jul 18, 2010 2:42 am
by white-shadow
use inspect function.
1) inspect string replacing leading " " by " ". it will remove all spaces but still there will be one space.
so after this use move string(2:lenghth of string) to string2. it will copy ur string value in string2.
i am also a begineer so not sure. but i think it will work.

Re: Cobol - how to delete spaces at starting postion in di

PostPosted: Sun Jul 18, 2010 3:25 am
by dick scherrer
Hello,

Until kavalisubbarao clarifies the request, it is difficult to offer suggestions.

Suggest you run a few experiments with the code you suggested. You will (probably) be surprised at the "output". . .

Keep in mind that "length of string" will be the same regardless of the number of leading spaces. . . Suggest rereading the reply from Robert.

Re: Cobol - how to delete spaces at starting postion in di

PostPosted: Sun Jul 18, 2010 6:22 am
by Robert Sample
white shadow, ponder upon the difference between a variable (COBOL terminology) and a string (Java / C / .Net terminology). The length of a string can be 0, 1, 2, ... bytes depending upon where the terminating null (AKA LOW-VALUES in COBOL) occurs. This is not the case in COBOL. A COBOL variable defined as PIC X(60) will always contain sixty bytes -- not 59, not 1 -- 60 no more and no less. The only exception is an OCCURS DEPENDING ON (ODO) in a LINKAGE SECTION or FILE SECTION where the actual number of bytes for the variable will be whatever is in the ODO variable. A WORKING-STORAGE section ODO always reserves the maximum number of bytes, although accessing the bytes between the current ODO number and the maximum is not recommended.

Furthermore, reference modification allows for moving to the length of the variable. This is valid COBOL:
MOVE WS-VAR2 ( 2 : ) TO WS-VAR3.

Re: Cobol - how to delete spaces at starting postion in di

PostPosted: Sun Jul 18, 2010 10:30 am
by white-shadow
sorry, i meant that only. length of the string means size of the variable declared in the picture class.