Can sub-string be used in SELECT statement?

Question:
Hi Sapfans,
I am creating a ABAP list and want to use the following statement.
select matnr(2,3) into wk_matnr
from mara.
But it does work. Do you know alternative way to do it?
Thanks.
Answer:
No, You cannot use substr in normal SELECTS. Instead you can use in Native SQL statements using EXEC..ENDEXEC command. Look at the following sample code.
data : begin of itab occurs 0,
str(3),
end of itab.
data : begin of w_itab,
str(3),
end of w_itab.
exec sql performing collect_data.
select substr(matnr,2,3)
from mara
into :w_itab
endexec.
loop at itab.
write : / itab.
endloop.
form collect_data.
itab-str = w_itab-str.
append itab.
clear itab.
endform.
regards
TandT
Hi Sapfans,
I am creating a ABAP list and want to use the following statement.
select matnr(2,3) into wk_matnr
from mara.
But it does work. Do you know alternative way to do it?
Thanks.
Answer:
Thanks tandt
Heard about that the native sql statement is database dependent.
So native sql stat. suits for MS SQL database, that may not work in Oracle SQL database. Do I right?
If my company wants to change from MS SQL database to Oracle, do we have to change all of these SQL statement in programs for using Oracle? or any another good alternative. Perdon me to ask such an fussy question.
tandt, thanks again for you answer , i will apply it in my program.
Thanks.
Answer:
Why not select the entire MATNR field and then do your processing on that ? (Unless you've got the same construct in the Where clause). The amount of programming to select a substring directly from the database does not warrent the work especially if the code then becomes database dependant.
R
Answer:
Hi R,
Thanks for ur remind.
Just feel it is convenient sometimes and Hope my company not change the database as long as I am in this company
Thanks for you reply, mate
Answer:
Well got the problem too...
This is my select-statement:
Well, I know that I'm able to use sign 'CP' with a range, that's how I do now.
Huh? The code fragment you posted, which is the only information we have to go on, most definitely does not do that.
Answer:
Well the code I posted should only be an example waht I want to do... The usage of CP as I do now is not what I want to do in future...
      IF sy-subrc NE 0.
* Für Übergangszeit sind auch Daten aus CO-PA zulässig,
* ansonsten kein Bezug möglich
        IF wa_gakopf_neu-werks EQ '0010'.
          " Rangetabelle für Seriennummer "Pseudo-Substring"
          DATA: s_man2    LIKE RANGE OF wa_ce40010-wwmnr,
                wa_man2   LIKE LINE OF s_man2.
          " CO-PA Werte für Wirtgen
          DATA: BEGIN OF i_wirtgen,
                  wwrnr TYPE ce40010-wwrnr,
                  wwrpo TYPE ce40010-wwrpo,
                  wwanr TYPE ce40010-wwanr,
                  wwart TYPE ce40010-wwart,
                  kunre TYPE ce40010-kunre,
                  wwp05 TYPE ce40010-wwp05,
                  wwmnr TYPE ce40010-wwmnr,
                END OF i_wirtgen.
          DATA: it_wirtgen LIKE TABLE OF i_wirtgen,
                wa_wirtgen LIKE LINE OF it_wirtgen.
          IF NOT wa_matnr-low IS INITIAL.
            CLEAR: s_matnr[].
            wa_matnr-sign   = 'I'.
            wa_matnr-option = 'EQ'.
            wa_matnr-low    = wa_matnr-low+8(10).
            APPEND wa_matnr TO s_matnr.
          ENDIF.
          IF NOT wa_vbeln-low IS INITIAL.
            CLEAR: s_vbeln[].
            wa_vbeln-sign   = 'I'.
            wa_vbeln-option = 'EQ'.
            wa_vbeln-low    = wa_vbeln-low+2(8).
            APPEND wa_vbeln TO s_vbeln.
          ENDIF.
          IF NOT wa_aubel-low IS INITIAL.
            CLEAR: s_aubel[].
            wa_aubel-sign   = 'I'.
            wa_aubel-option = 'EQ'.
            wa_aubel-low    = wa_aubel-low+4(6).
            APPEND wa_aubel TO s_aubel.
          ENDIF.
          IF NOT wa_manr-low IS INITIAL.
            CLEAR: s_manr[], s_man2[].
            wa_man2-sign   = 'I'.
            wa_man2-option = 'CP'.
            CONCATENATE '*' wa_manr-low INTO wa_man2-low.
            APPEND wa_man2 TO s_man2.
          ENDIF.
          SELECT DISTINCT
                 a~wwrnr
                 a~wwrpo
                 a~wwanr
                 a~wwart
                 a~kunre
                 a~wwp05
                 a~wwmnr
          FROM ce40010 AS a
          INTO CORRESPONDING FIELDS OF TABLE it_wirtgen
          WHERE   a~bukrs       EQ '0010'
          AND     a~wwrnr       IN s_vbeln
          AND     a~wwart       IN s_matnr
          AND     a~wwanr       IN s_aubel
          AND     a~kunre       IN s_kunag
          AND     a~wwp05       IN s_breim
          AND     a~wwmnr       IN s_man2.
          IF sy-subrc NE 0.
            MESSAGE i000(zwisdga) WITH 'Kein Auftrag gefunden.'.
          ELSE.
            LOOP AT it_wirtgen INTO wa_wirtgen.
              CLEAR: wa_auftrag.
              IF wa_wirtgen-wwrnr CP '0*'.
                CONCATENATE '1' wa_wirtgen-wwrnr INTO wa_auftrag-vbeln.
              ELSE.
                wa_auftrag-vbeln   = wa_wirtgen-wwrnr.
              ENDIF.
              wa_auftrag-posnr   = wa_wirtgen-wwrpo.
              wa_auftrag-aubel   = wa_wirtgen-wwanr.
*              wa_auftrag-aupos   = wa_wirtgen-
              wa_auftrag-matnr   = wa_wirtgen-wwart.
*              wa_auftrag-arktx   = wa_wirtgen-
              wa_auftrag-kunag   = wa_wirtgen-kunre.
              wa_auftrag-kunrg   = wa_wirtgen-kunre.
              wa_auftrag-zzbreim = wa_wirtgen-wwp05.
              wa_auftrag-zzmanr  = wa_wirtgen-wwmnr+4(4).
              CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                   EXPORTING
                        input  = wa_auftrag-matnr
                   IMPORTING
                        output = wa_auftrag-matnr.
              APPEND wa_auftrag TO it_auftrag.
            ENDLOOP.
            CALL SCREEN '2094' STARTING AT 10 5 ENDING AT 170 26.
            LEAVE TO SCREEN 0.
          ENDIF.
This is what I'm doing now. As you can see the COPA will only be read if sy-subrc ne 0 (this is the result from trying to catch values from vbrp first)
_________________
Juergen Limbach

More Articles:

'SXPG_COMMAND_EXECUTE'?
Client Doubt !?
Join v FOR ALL ENTRIES IN?
BAPI?
Park invoice for non-PO invoices via BAPI?
"submit 'program' to sap-spool and return" & c?