0

I have a field called 'UCN' which has 6 character. This Field can have both Character and Numeric Value like "A123Y5" or "12345Y" or "G23561" some thing Like this.

We need to print the data from here with Pipe as A|1|2|3|Y|5.

I am able to put Integer with 'using' keyword, but unable to put both together.

Please if anyone can help Mukesh

Mukesh
  • 5
  • 1
  • 5

3 Answers3

0

I don't think there's a short cut. You need:

PRINT ucn[1], '|', ucn[2], '|', ucn[3], '|', ucn[4], '|', ucn[5], '|', ucn[6]

If it was marginally longer, you might use a loop instead; that has its own fiddliness.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
0

If you are working for who I think you are working for, I can give you an answer using some Genero extensions to 4GL. Create a library function like ...

FUNCTION insert_between_each_char(str,delimiter)
DEFINE str STRING
DEFINE delimiter CHAR(1)

DEFINE sb base.StringBuffer
DEFINE i INTEGER

    LET sb = base.StringBuffer.create()
    CALL sb.append(str)
    FOR i = sb.getLength() TO 2 STEP -1
        CALL sb.insertAt(i,delimiter)
    END FOR
    RETURN sb.toString()
END FUNCTION

... and then your code becomes

PRINT insert_between_each_char(ucn,"|")
fourjs.reuben
  • 286
  • 3
  • 3
0

Here is the code to loop like mentioned by Jonathan:

   DEFINE 
      l_result   char(512),
      l_sel      LIKE table.UCN,
      i          integer

     LET l_sel = "A123Y5" #Or select into l_sel

     FOR i = 1 to length(l_sel)
        IF i < length(l_sel)
        THEN
           LET l_result = l_result, l_sel[i], "|"
        END IF
     END FOR

     PRINT l_result
Moses Davidowitz
  • 982
  • 11
  • 28