ABAP Development

Creating and Adding Word document dynamically to the released task of Notification

Introduction

This Blog Post discusses about the approach of completing one of the requirement related to SAP Notification and Task Creation.

In simple terms if I explain what is SAP Notification and Tasks are is that Notification is a bundle of tasks that contains predefined functionality to be performed by each, now in order to activate the task it has to be released for further processing.

Now let’s discuss what was the requirement and what approach did I took to accomplish it.

Requirement

Requirement was to create notification via IW51 transaction and then to create tasks corresponding to it, once done user will open the task tab where he/she gets to see all the tasks being generated and simultaneously according to his/her choice will release few or all the tasks.

As soon as user releases the task at background a word document with dynamic and static data needs to be generated with the client logo in it and has to be attached to the same task.

Approach

Now looking at the requirement there are few major points that comes up and rest of the solution revolves around it.

a) Generating the Word document dynamically containing dynamic and static data.

b) Attaching the generated Word Document with the released Task.

c) Finally triggering the above two steps in a combination as soon as the Notification Task gets released.

a) Generating the Word document dynamically containing dynamic and static data.

RTF or Rich Text File was created by Microsoft and as the name suggest, it’s rich in formatting, styles,etc. than the usual text file. Best thing about RTF (file extension: .rtf) is, if saved as ‘.doc’ or ‘.docx’, it will be converted to the mentioned format without any issue.

To create RTF file either we can use any word processor(not in our case) or we can use RTF Code (RTF code consists of plain text, commands, escapes, and groups: Plain text contains seven bit (US ASCII) characters except for \, {, and }. ) within the ABAP code when we are clubbing the data in an internal table with which the file is to be generated.

NOTE: As we are using some sort of code (RTF Code), therefore, there’s need of program/software to render it. Nothing to worry here, MS Word, OpenOffice, or any word processor software will do us this favor.

For this requirement, I am using static text stored in SE61 as General Text. But there’s a clause to it that, I have written the RTF code as needed in text itself, so that when it’s call in ABAP we will have everything in internal table. In my opinion, in case of dynamic text too with certain template, we can use the same method but keep some placeholder which is unique and can be replaced easily by modifying the table itself in code if placeholder exists for that line.

Let ZSCM_TEXT_MVTMSG is General Text created using Edit Documents TCODE (SE61). Below is the data:

{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0{\pard \qc
{\pict\pngblip
89504E470D0A1A0A0000000D494844520000010E0000005A0802000000C6BB2FA7000000017352474200AECE1CE90000000467414D410000B18F0BFC6105000000097048597300000EC300000EC301C76FA8640000155D49444154785EED9B09701DD595861F90090E79DDB7B7273304061C60180203242435052105041754650666268C191617CC6420A99A9A7108018C654B32D818E4455E6463E37D41D846DE648CF77D41B6B5CBFB22CBB6BC62BC1B2FF2D2F39F7BFBF56BBDC5EE84A7648A9CAAAF5452F73DE79E7BEEF9EFBDDDEF29F27E24C630CC1561A9304C28582A0C130A960AC38482A5C230A160A9304C28582A0C130A960AC38482A5C230A160A9304C28582A0C130A960AC38482A5C230A160A9304C28582A0C130A960AC38482A5C230A160A9304C28582A0C130A960AC38482A5C230A160A9304C28582A0C130A960AC38482A5C230A160A9304C28582A0C130A960AC38482A5C230A160A9304C28582A0C130A960AC38482A5C230A160A9304C28582A0C138AAC49E5BD48AC5700FC79990669EF267950A4B6545CDE1B486AE0B7095E4FC537BF0C491E7CCF97410510B45284B1057F846D5A1310B24710F4906A9574D76F10BC9E96902DFD663EB812DE796B901DA9508857394444911CB71CA453A8EE52B3E4BB3D23B177E977DF83E46ABA885BF0E63756EDDFF3DBA478537F52772A9E780345228C2464B31E297D25A19CF8232D94EDE94A06648F6A08F18E7CAEA2D1814CE6015BFC99649ED1D6B74AA428C1157AF44183F7E263F4FE6C799742CA94DE84610A57397E4B907C3741729C7193A4660102612893AC931DA96054A3FE47B80D9ABB4B73776B9726591FC88B7E83B723B1596335773FEE46DD8D62D3F34E41FC1626F57DCD197A83BD608CEEEED3DCC600C7F555373983DA3A7D54B3386F479C451334B789FA726BB5F27F88750FDC0598C8C2570CF770D4DD197577884D2F3ABD6512DF89C4A68D9461047B51EC8FBA1F58FD34A7E8EA167D2501CFC50F987B2AA2D4FB81A83BD45617836D7CD0235CF5319C0FEFB7EACA34774FA0BB5D51779BF1691B67904D7A0BE62A60EBF413CEA03BECFA89BABB3760BB27EACE33E7DDE50CD43CAD06ADE0AAC870463D691D582953E45BEDD59BA798A551678046F59A29660532BC6A014C40D49D6D4E8FD122E2DF25DB874DF758727AD1F5076FEAEEA168A2D32098FA06E313B91EA1E588A7CCA3F5519AC1A46618DD7C63E1234EFF6BA919DCA247FC2CBCD1AE9C2E434A6AAF38A4ED7BDD1E922E93D9226B07B0DCEF594DB375B74A732B3477B95EF9682C3F7E0BE32CB8C33A55ADB96B35B75A3B5D6294E678A9C7CFE29BED6513BDA2776B34775D1CFC89F6DB81A87ECCEE7F4DA2823191738B655F95DA8545FAB21FA691CAFB2F18EE46E9618DA8E94025853060B86C8A8E18DC353ADD4217AAAF3AD9123F1BB486FFA4BE32651C9E07FDC8DA36075DEB687FAED086DB4C6587EE463E686D5C8C12917DF9DD018C143D42308B8CA53F76FAC81DC637844F2AA6C7CD2DB3651DA071D01671E2CFC6A83BD32CBBDD41EF681FB7724A3A987B5747DDADD20A2D9549BD46E9C2C09BB43363CC99B75F412D887CC96499A82AAD798698FB035C49DC25C317D3A417B339B92FA5C54B6F7036C106FC34666BB460612A273C631C419BB53A354647AA8D8A133446CF0D3727DE482D55A845EDECFA59B825DB570686A668D00F16D823324FDCD7276B52C11238EA5746B3AA800A8ABB6F7C32909A923C41C303E562DDD3745DCD6BFF5BAC5DE5324132B327461BD55D8CFA3CA33ED7A82A169417080F5635DAE6979CA2B8C3AF2315AF02D66A1797E87BFA1A355D8DFA6E46752FE3CC1A2972F455A1ADFFA53743419F0A780E29157818748F79E60B39BB0875B5BEBFD8A8C995A3EB62540ED7DDCDB2A450F48BC5AAF6B4302B3F708864963C671C4305209F0869AB7EA4D858976BD4C1B69B51DFC3D8BF48A3D1358A6D1DED41D250594DEA689CC74E8281C0ED52D1F0BE518B01E61975DD8C2DA5BABB1E3D52C95E986A94DD412669C7085A4865BA98F377295249975E486562A1940AAEAFD00F0E898F575180E0ADA172154072C677300E231848A55A3B35C6A87E8B86565B60ECFE447862DB1C6D1E64F797EDD163D12D76DD4C99CC4AEDE22CB1F16D1A94EF7CC3BBE6FC9FD9FD32CC4556C89A5440B788B3065BA4CCEFC5CF8CC5F7D2C642196C6BED5A4817C1991116A6D65B2A6276F504A10AD7AD158DFF6B95DC10CBC51624E9F25D7BD67F1BE729EF72CEE6790ED15116A452A59D9B2266DE94F396EC0B9D4EEE6A5051A27D8D7EB8C81E2C6728E85301CF61A4822BEFFE8DD5B44A167A957661B1D8F0A2352C1AEB1A1F5D67DBAE2814EE2659BBEBB4F363AC8937385853608B7EFB3F689E44F0153AA4726196D8946B8D8BD218317CC5F09F9B2BDF300E7D2E9A7E4DF9A4EE22B1010F492B4AA67EA6D4A87ACAC6C1354F76879FBDFEDEDA3442D0028C1E3769A77BDAFDFF2AFD18C1D7954AA576698E58FA13A7737CBC3EAAC71652D9A8ED7C3AF6BABCDB0DA3F8A9B50BC71335179B8C52E9163D26A452AB35F7B3B010A371D033B2973A1159249B52A140DB9B74D8400AAA44532E2D7818C3946EA259AED66EB5A87BD0C108D118C91AF5BC71BC5CEE1B75DAA901B47E04E703A0E54C4882D61872B827CF1A2C0F2A59914A5205BC7595DDB45A0689CD6D9C59F22D9A21DFA10F3C87914A8F8833B1BB5C05E0B05C6BEC6463D3083A8455C177ECB5D3653008B24AD43EE32D8ADD23CEEA15F23A92B64CAF7D9682471DC0C4B745F6F2B08D3F6097DCE40F2DB660AADC4CD0E362B1F6497285667E8FF8BDCFDDD6D639F12AAC140BEF75904CDF6D902C48659E58F9B093342F3E4952697AC18198D5AD8288FDE96BC60525E906517E2B4D2E7A0C4AE5FC40ABF8BB1975DE4A64532A000BDEDAF9512A6264B9CC987B572CFF266B47994C3ACE12E32DB45185D5FD2A67512F7101534B19D12BEFA695CFF7A340F6F3AFB18EEE946D6AB553A3CDD21B683E5A432AF911BB064741D459AD7E6CA439B6659DF9C07318A9E47DCB590719A808171AF36EA62523D8005698E9C1F79B27B7C9D1ADD70EE55B1F5E4717DFBCCDA4E7135CAC127BF3E85135AD68011A2348B8C2EFB9D7DA87B7A844E927869B931C5257B0319A41C0935F34CE222D68B6596B7A29F19C93C49F512AEF449CD297CC9378B0C1DD9D6289A0AED1E3374D2A88BEEFE3F18DA54E6F78C59EF1B2711425889CEED4ABEFF2F4809117DE6D6FC6E9199381EA5C630DCB509AF911A70EB6388AE0183345CCBE9712D71A5279B59DE53DAE54EB5FBEEF608B232729E0E215A5823F7BFFDC3CB64C7AABD24F0DB78BE3078FA466FD2CBB418DAE563B37D41A9D4303195DA0D33109B60BC5EAF6546D69AB39085CF579DEF08E739562C7ABE9E34786473E6C1D84671468BD76BA47C607AD60A2CE7E22A6B7CDC10109C7544597484EB7A7CC2B4865B6587C5FECF7012BE027E13252E9FA6D7B7E2F839C20CE5AF323E9164106A572AE37D65C3A3CFB9EB146A71D4816C9B254902F3C5CAE2A8B52962BB55373C4570B058D195BCA34BB4B7CD691B2A1EDAD3D7880C16180761B1BC34E5B1028E5D9E3E9F9815A2E142B1FA3D2C98A54A8026239984B4C7CA79BAD2FE64987B8B54A5BFD00394C1B0F3C5F512AA88331BF11A7D571AE423FDAD9C6234AAA3758150A67F51439FDE87AA6F9713B9C4E9D451313620EBE7A4231218149A838A9467B53F5538FCB44DDD30E4A27B547A47DA01F3CD2FE7162934F229128AA66EDD26AFD128683DF2597CAF58BF813B9CD241569E59295EE5921B0C5DE333AFC2749A5F1C958A7480E8683E928C543A37ACDB3357AEC75EF4D1D4848851CEA88211092D8FA1BFA4421ED58B24596A502908BA207ADB3EA3040B5227FD9263EBF23710821A93C26A5229F5C95547C0F411252811F4845AEB25990CA1A69BE5DBEA4063805E14F0A55FFB293FD46BA3A53C07328A9FC5A9C56C7B94A4F2AC1060A18161A4E39A452ADA462402AB9117B134542419E1C6F4DBC8EEA0F8DF3DA3A07B058EC8D070C9AA26EA351F1047DF486B39657A3E871B9A8FB37928ADF910FE28454B6AAE091848961A4225FFBE2171C95832048752BBD546441A34DD0E4903159B681FF16524163CC941A144E9ED851E116B62556FF6F534BB4479001A9C86240D9F89EB7E9077AD83898281DB612D9970A52D6F31A676ABE7A352953B6513BFE9A8DA2F76785A4A276152595719793CA67E3E2BBCA7CB1FCD1EC49C5AF0035EB88B3417C76359D3482AE9280E73F6C578154DECC2C15E19497C6A532DD2CB999A452AFDE9B556BA74ACC52D3ABAD6EF759C7F1AC8F3242C0C8980A788BA8FF27BB4866691276152595F8AE12EC4B81381352A1152AD4AE72E973FDAB59E2C834FDD8748FA353F5A30B64BD66948AE696EB67E6E809AB997AF3C714AAEA2E592A4A540889FEC4939BBEAD2325D67FDC8255422AE874B97E6C867E54799EA19F9A61D43E9F78DBDE4A645F2A004A1874ABB913430248E81A637AB4C5CB16FC3EF8116BF73CAF26DCC976DA03034011CC9FEC15D3451C487E4457FE30A9AC15B5A952C1A162B97E78ACD83150EC9FA15FA429D7DC4DA2E671C7FF38282DB815462A23FE437CF5B92795637936C24B1D1DAC7A0BA7A24C4E7F8D76618435E67A7AAF3577ACACE32AED7C9958708F37B4B7A3CEE7EF1BBB3F143B8788DD23057D7E8580378BBA5F50FDA1A4C6BF2D0F6018C80AB1EE3907594AED11692FFEB1D5B040AE50198257241285936AA998F1D739D869BBC5C98DE4E4FD4B8867951F3A58777C2BE0F7D5422AE862AA681824768D1027D5565CA71FEC657D14A3F66A14F8A5C5B34A1FAB501ED87CCFC852DA81649156910A4D40CC5EFA819C720CACAF35E03B2D36476A7097BD395EB56E5DC6C77A9CDD77A83635FAD98F8DB2DBA92C3091F386C4A5B2505F12AF271F64EDDD7F8FCFE52A51F1CF9E50831570AE54947D8F2AA0F0366BD394F82BD48D89D7D96981E7308FF5BD1E354F2C91EB2E1EEBC7A4FF9406578A6EB3F66314E8B75E3BD9C71A6920C2D8E8BCF863FD5251F9247DD8A2CA05B7F0B8428F3DD759FBD58B93B854E0AAD7B37269C0C56AB1E377E91FEB51CAE39E348FA91E3768875F0B25953FC11BB09DFF1A7B4D3E9A9775D19BB1BDE0FA36ED4437BB28FEE93B7A0C4AE59BF0064C41537BBDBD62842795B403CBCFB1AB46AACF657142D517462953C10600092A78C8A40709B4A9117BF26DF5D53254CF0C4C09A61CF5B44CAF7982D695A021ADEBB982565908E033B1F8A7F1B5395D05F48838C58F5B8771BCA1CAA60F49D3BEB05220A42B4A0574FDBE7D7091941F3439DB98D62659CCB04290C35F917AC6E86A716AF28ABEE7A3F15788D5FAC19ED6F06B12E71080BE065C6F7DD1522AB8F8D6BD96BB435EACD3BFEC678D6D6905A894DBD8B3DE919F42A2C4EB8C253FA0EE68B252F8134B45BD0123B7C25E355CD0610C73516ECCFC5B2F42DCFACB950AD23AE5B7C669E41AC9AAD58E0DA3290F6616EDDF74EC0DEA751012B752D43EEDC04A25AEB0834117615EA57DD987DEC606E7F2F58843C73FF920D43CD99875A75737992A00C79E351FC7B5B752D4B4F75E6AA782AEC348056E17605355EBF75A7DBBFC083258BB1848FE3DD6C1859E9CDC39C6ECFBA880E00D4B46FD8A28F947302B44DD33740AF76DD1577F3B7957C1C58248AC6E69C2AABC3D6DA470A8ACE016B92DC696A25E61A3164BAD91FAFF2FA9E03A86897DEF04C283E70DDAB9EE365AA23BF0972B15B4E9798BDD3053B6916BE1BE1E46694E4E6779F4EC12C919F088B9BE247EB75A3F39CC1E718DE3CF7DD788BD8F4E29541997CAF5DD9DAD11D7D28B76D8BE76A3BD6DB43CB8C3B046EC2B487CE134530560260A3B98544398A11AFD506F6B40868D052D835239FB8E8D1E73E32766802957B3DBF33EF3348A060E2BF54BABF41D9DAC916DBC08DF8AE40CED681C9843B3AEC6DEF8AA3D30DE237E0EBCD338BDDF1BF8F945FA911ED69036B0225B64A6EF2FE21FA104A44256BF34BC8DA5466F9EA7AF7F96BED882033DCE6CE0932EE2289489B123A475A2E2091BF50DC3E0E87CB2209574CF2A40693E9354E0A4573B2BF175A7F54689748B1E2FFFAC02B0C4A49DB26CF167930A400A86BD64D07900654735AA9D9BE3BD69393A553FB914858299D0E91BA92B4DF55D20F22CA15AEC28E84BFB6880125FA39F9EA51F85ED34FDF05C253052CBA579E6A737260C2F5301DD22F64ECC315C5569173E3516DE93F8378120E8372115C4BC8C3AF55EC54CD74F7CA637E55B632C2A05D4047D98D88448A87450135E8418DD14F9D0AFAA61BB7662883546568F0A123F11F0D8FF3269746800DB4AFD946F3B4D3FAE9E82E036FE060C5191D5D5CEFC713ABD01C72D385FA59F28F36283D539B852DBE61EB1F365FAE61866C4CF67125F572A0820E90D1828C34F73A6FC1A4126A9A8AE3FED6434D37749E9BB6A475EA6B7A32DA4824E836FC02427E6886D9DEC0FE5F7F6FD38B34B2B4A65E528B9B4AFD32E145B83D34905CD7031FF46FB546394FED1053521A5E58179828A0E44DD0F69E54E9D574C4C9F9FC9FF9AC0121BB485210A625FD45D614E682930AA80523997107099987B67A2023079C5AF0B9A7ED86ED4F7C69F8BD45D1FCC59F14F4C7A8984EEA4AEBC4E15309F624CBBC3EB143EFBE059EB78941EB79246074384BD433BF47B7AB1AB6ADDEF05BFC3C3B0FBCD43DBE25FE04FB2C518B7273E57417B05AAB0E415C33D12A548D02C299F08A34E543E45E7A2A41E930826EAC24C31EFAE14A9608DDB220755216A9F4948657291FC900099C12DF4E8F70E500CB5C6FCB6E40A99A12FE1AB665BB43D1D135281F37E0FD83B67CBF50E77F71A1FC971157DDF5E373B90F6E0D0C056FDD03BF6C86BC9B31F677669CD5D65B85C96F0B430D01A1C4D2F77B4446ABAD2666AED464DC8CF771518FFE9023B57EEB399E6153E3B477286FCA3D98C9D2761ABB98DE6A848CE9B2D7502A80226798BE5B9A9624EFC19468143DD8E46F841EAF523C5E647224DDEC9DBAD76F5787A0EF143F5C1608F0DB026C43C43344684386E15B533BFC032196CB95EDBFB5CECB7F2C0967674B80227C84C7E3B7B2316781C697CDB0AEDE22C63D13DF4D60845EFDBE2178021BF11713E7AD63C89920D98B88BF5B50FC57E279F6A544BBFAF541289AAD64E8CB32645C9AD7F97A4729F751A23C202BF3AB1AB60B0FD7F2530343FD420D4B8DC98DBD6DB55267430BEA48FFCE9D4B0FB85161F0475C7C6D2599C8550D160BB587E33A9EBBDB6F6B2611452925B091D62F7E7DB23DBA42FB3ACD02A5201481C86A7BE9FA3F684A40649A03D8A46B5F78121CDCA959025956C1B9CDA207E543009EA4481095377114CAA4E14081505AA9AA58298530D31FCD4D1F9EBE8E5410650DC49B6083EB8CCA782E1239224934C0FD969094E5F6A321195EF3F28578C545D4C4B30E7C8929F93A04E1468E6CFA91A69B0A2D2026FADA713D05A5261986F182C158609054B856142C152619850B0541826142C158609054B856142C152619850B0541826142C158609054B856142C152619850B0541826142C158609054B856142C152619850B0541826142C158609054B856142C152619850B0541826142C158609054B856142C152619850B0541826142C158609054B856142C152619850B0541826142C158609054B856142C152619850B0541826142C1586094124F67F18DE40020F807B860000000049454E44AE426082}\par }
{\pard {\line}{\line}{\b As per example given, our static text starts from here!! }{\line}
This is an example of how the word file will look like whence generated. The image will be at the top and at the center of the Page.{\line}Below that, there will be one paragraph where the first line will be of style bold and rest of the text will be in regular style with font family as Helvetica and font size as 12pt.
\par }}

This may seems to be a mess but it isn’t.

Let’s decode the above text which consist the data and RTF Code:

  • { – Marks the starting of document, property, etc.
  • RTF – represents the file format like we do for HTML or XML.
  • ANSI – Character Encoding
  • {\pard \qc – This marks start of paragraph with alignment as center (qc is for center alignment).
  • \pict\pngblip – pict represent that we are going to add a picture in our document and pngblip means it’s of type png.
  • Long paragraph which seems to be a bag of random number and alphabets, is actually the image in HEX code. You can easily convert any image or file in hex using online tools. I will provide the links at the end.
  • \par } – This refers to end of paragraph. In our case, we are ending a center aligned paragraph which consist an image.
  • {\line} – For linefeed. It’s like
    of html.
  • {\b text }– to bold the text which is in the scope of these brackets

ABAP Code:

CALL FUNCTION 'DOCU_GET'
  EXPORTING
*   EXTEND_EXCEPT     = ' '
    id                = 'TX'
    langu             = sy-langu
    object            = 'Z**'
  TABLES
    line              = lt_lines
  EXCEPTIONS
    no_docu_on_screen = 1
    no_docu_self_def  = 2
    no_docu_temp      = 3
    ret_code          = 4
    OTHERS            = 5.

We can use the above FM, to have our text in lt_lines internal table and using this, we can manipulate it as required to incorporate dynamic text. At the end, we can use this internal table, to download the file on our system, or share it using email via ABAP, etc. keeping the format/extension as ‘.doc’/’.docx’/’.rtf’.

Below is the screenshot of final output generated by downloading the above internal table to system using extension as ‘.doc’:

b) Attaching the generated Word Document with the released Task.

This is a piece of code showing the variables used and the values being passed to each of them i.e (lv_qmnum is Notification Number , lv_manum is Task Number , gc_doc_file_name is Filename).

Here is the complete code for reference:

*&---------------------------------------------------------------------*
*& Report  ZTEST_NOTIF_TASK_UPDATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zgk_mm.

DATA:lv_fm_name        TYPE rs38l_fnam,
     ls_control_param  TYPE ssfctrlop,
     ls_job_options    TYPE ssfcrescl,
     ls_composer_param TYPE ssfcompop,
     lt_otf            TYPE TABLE OF itcoo,
     lt_lines          TYPE TABLE OF tline,
     wa_buffer         TYPE xstring,
     wa_buffer_ref     TYPE string.

TYPES:BEGIN OF ty_tdline,
        tdline TYPE char255,
      END OF ty_tdline.

DATA:
  gc_x                       TYPE char1 VALUE 'X',
  gv_doc_id                  TYPE saeardoid,
  lt_tdline                  TYPE TABLE OF ty_tdline,
  lw_tdline                  TYPE ty_tdline,
  gc_doc_file_name(400)      TYPE c,
  gc_doc_file_path(400)      TYPE c,
  gv_doc_file_path_name(200) TYPE c,
  gv_doc_type                TYPE toadv-doc_type,
  gv_filedesc                TYPE toaat-descr,
  gv_filename                TYPE toaat-filename,
  gv_urldes(50)               TYPE c,
  gv_return_ident            TYPE zstr_return_msg,
  gv_sap_object              TYPE saeanwdid,
  gv_ar_object               TYPE saeobjart,
  gv_object_id               TYPE saeobjid,
  gv_archive_id              TYPE saearchivi,
  lines                      TYPE i,
  l_v_length                 TYPE syindex,
  t_data                     TYPE STANDARD TABLE OF tbl1024,
  lt_length                  TYPE i,
  lv_xstring                 TYPE xstring,
  lv_qmnum                   TYPE qmnum,
  lv_manum                   TYPE manum.

DATA:
lv_hostname                   TYPE SO_TEXT255.

*---Get the file contents from saxexchange
lv_qmnum = '**'.
lv_manum = '**'.
CONCATENATE lv_qmnum lv_manum INTO gv_object_id.
gc_doc_file_path = '/tmp/'.
*gc_doc_file_name = '**.doc'.
CONCATENATE 'Notif_'lv_qmnum'_'lv_manum'.doc' INTO gc_doc_file_name.
gv_filename = gc_doc_file_name.
gv_urldes = gc_doc_file_name.
gv_filedesc = 'CIT-CID doc #4'.
gv_doc_type = 'doc'.
TRANSLATE gv_doc_type TO UPPER CASE.
CONCATENATE gc_doc_file_path gc_doc_file_name INTO gv_doc_file_path_name.
gv_sap_object = 'QMSM'.

gv_ar_object = 'Z**'.
gv_archive_id = 'Z1'.

CALL FUNCTION 'DOCU_GET'
  EXPORTING
*   EXTEND_EXCEPT     = ' '
    id                = 'TX'
    langu             = sy-langu
    object            = '**'
  TABLES
    line              = lt_lines
  EXCEPTIONS
    no_docu_on_screen = 1
    no_docu_self_def  = 2
    no_docu_temp      = 3
    ret_code          = 4
    OTHERS            = 5.

IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.



LOOP AT lt_lines ASSIGNING <lfs_line>.
  REPLACE ALL OCCURRENCES OF ',' IN <lfs_line> WITH space.
  APPEND INITIAL LINE TO lt_tdline ASSIGNING FIELD-SYMBOL(<lfs>).
  IF <lfs> IS ASSIGNED.
    <lfs>-tdline =  <lfs_line>-tdline.
  ENDIF.
ENDLOOP.


CALL FUNCTION 'SCMS_TEXT_TO_BINARY'
  IMPORTING
    output_length = l_v_length
  TABLES
    text_tab      = lt_tdline
    binary_tab    = t_data
  EXCEPTIONS
    failed        = 1
    OTHERS        = 2.

IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    input_length = l_v_length
  IMPORTING
    buffer       = wa_buffer
  TABLES
    binary_tab   = t_data
  EXCEPTIONS
    failed       = 1
    OTHERS       = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

*
IF sy-subrc = 0.
*
  CALL FUNCTION 'ZOTX_UPLOAD_DOC_XSTRING'
    EXPORTING
      sap_object            = gv_sap_object
      ar_object             = gv_ar_object
      filename              = gv_filename
      file_extension        = gv_doc_type
      archive_id            = gv_archive_id
      object_id             = gv_object_id
      file_description      = gv_filedesc
      file_contents         = wa_buffer
    IMPORTING
      doc_id                = gv_doc_id
      x_return_ident        = gv_return_ident
    EXCEPTIONS
      error_archiv          = 1
      error_config          = 2
      error_http            = 3
      error_kernel          = 4
      error_connectiontable = 5
      OTHERS                = 6.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  CALL FUNCTION 'ZOTX_ADD_URLLINK_TO_OBJ'
    EXPORTING
      i_objecttype = 'QMSM'
      i_objectkey  = '**' (combination of Notification + Task )
      i_url        = '**'
      i_urldes     = gv_urldes.

 ENDIF.

Note: In the above code ** means you need to provide your own created variable name here.

FUNCTION ZOTX_UPLOAD_DOC_XSTRING.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(SAP_OBJECT) TYPE  SAEANWDID
*"     VALUE(AR_OBJECT) TYPE  SAEOBJART
*"     VALUE(FILENAME) TYPE  TOAAT-FILENAME
*"     VALUE(FILE_EXTENSION) TYPE  TOADV-DOC_TYPE
*"     VALUE(ARCHIVE_ID) TYPE  SAEARCHIVI
*"     VALUE(OBJECT_ID) TYPE  SAEOBJID
*"     VALUE(FILE_DESCRIPTION) TYPE  TOAAT-DESCR
*"     VALUE(FILE_CONTENTS) TYPE  XSTRING
*"     VALUE(DOCUMENT_ATTRIBUTES) TYPE  STRING
*"  EXPORTING
*"     VALUE(DOC_ID) TYPE  SAEARDOID
*"     VALUE(X_RETURN_IDENT) TYPE  ZSTR_RETURN_MSG
*"  EXCEPTIONS
*"      ERROR_ARCHIV
*"      ERROR_CONFIG
*"      ERROR_HTTP
*"      ERROR_KERNEL
*"      ERROR_CONNECTIONTABLE
*"----------------------------------------------------------------------

DATA:
  ls_return                   TYPE zstr_return_msg,
  lv_doc_id                   TYPE saeardoid,
  lv_len                      TYPE i,
  t_data                      TYPE STANDARD TABLE OF tbl1024.

" convert xstring to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer        = FILE_CONTENTS
      IMPORTING
        output_length = lv_len
      TABLES
        binary_tab    = t_data.

CALL FUNCTION 'ZOTX_UPLOAD_DOC_RAW'
  EXPORTING
    SAP_OBJECT        = SAP_OBJECT
    AR_OBJECT         = AR_OBJECT
    FILENAME          = FILENAME
    FILE_EXTENSION    = FILE_EXTENSION
    ARCHIVE_ID        = ARCHIVE_ID
    OBJECT_ID         = OBJECT_ID
    FILE_DESCRIPTION  = FILE_DESCRIPTION
    FILE_LENGTH       = lv_len
    DOCUMENT_ATTRIBUTES = DOCUMENT_ATTRIBUTES
  IMPORTING
    DOC_ID            = lv_doc_id
    X_RETURN_IDENT    = ls_return
  TABLES
    FILE              = t_data
  EXCEPTIONS
    error_http   = 1
    error_archiv = 2
    error_kernel = 3
    error_config = 4
    OTHERS       = 5.


  DOC_ID            = lv_doc_id.
  X_RETURN_IDENT    = ls_return.

ENDFUNCTION.
FUNCTION ZOTX_ADD_URLLINK_TO_OBJ.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(I_OBJECTTYPE) TYPE  BORIDENT-OBJTYPE
*"     VALUE(I_OBJECTKEY) TYPE  BORIDENT-OBJKEY
*"     VALUE(I_URL) TYPE  SOLI-LINE
*"     VALUE(I_URLDES) TYPE  SOOD1-OBJDES
*"     VALUE(I_NOCOMMIT) TYPE  XFELD OPTIONAL
*"----------------------------------------------------------------------

*
*Local data definitions.

   data: l_owner         like      soud-usrnam,
         l_folderid      like      soodk,
         l_obj_id        like      soodk,
         l_objdata       like      sood1,

         lt_objcont      type table of soli with header line,
         lt_objhead      type table of soli with header line,

         l_object        like     borident,
         l_reldoc        like     borident,

         l_syst          like     syst.
*-----------------------------------------------------------------------
*
*1. Get folder id.
   l_owner = sy-uname.
   call function 'SO_FOLDER_ROOT_ID_GET'
     exporting
       owner                 = l_owner
       region                = 'B'
     importing
       folder_id             = l_folderid
     exceptions
       communication_failure = 1
       owner_not_exist       = 2
       system_failure        = 3
       x_error               = 4
       others                = 5.
   if sy-subrc <> 0.
     l_syst = syst.
*    perform collect_message using ot_return l_syst '1.FolderRoot'.
*    append ot_return.
     exit.
   endif.

*2. Insert object

   l_objdata-objla     = 'EN'.
   l_objdata-objdes    = i_urldes.
   l_objdata-objsns    = 'O'.

   concatenate '&KEY&' i_url into lt_objcont.
   append lt_objcont.

   call function 'SO_OBJECT_INSERT'
     exporting
       folder_id                  = l_folderid
       object_type                = 'URL'
       object_hd_change           = l_objdata
       owner                      = l_owner
     importing
       object_id                  = l_obj_id
     tables
       objcont                    = lt_objcont
       objhead                    = lt_objhead
     exceptions
       active_user_not_exist      = 1
       communication_failure      = 2
       component_not_available    = 3
       dl_name_exist              = 4
       folder_not_exist           = 5
       folder_no_authorization    = 6
       object_type_not_exist      = 7
       operation_no_authorization = 8
       owner_not_exist            = 9
       parameter_error            = 10
       substitute_not_active      = 11
       substitute_not_defined     = 12
       system_failure             = 13
       x_error                    = 14
       others                     = 15.
   if sy-subrc <> 0.
     l_syst = syst.
*    perform collect_message using ot_return l_syst '2.ObjectInsert'.
*    append ot_return.
     exit.
   endif.

*3. Create binary relation

   l_object-objkey  = i_objectkey.
   l_object-objtype = i_objecttype.

   concatenate l_folderid l_obj_id into l_reldoc-objkey.
   l_reldoc-objtype = 'MESSAGE'.

   call function 'BINARY_RELATION_CREATE'
     exporting
       obj_rolea      = l_object
       obj_roleb      = l_reldoc
       relationtype   = 'URL'
     exceptions
       no_model       = 1
       internal_error = 2
       unknown        = 3
       others         = 4.
   if sy-subrc <> 0.
     l_syst = syst.
*     perform collect_message using ot_return l_syst
*     '3.BinaryRelationCreate'.
*     append ot_return.
     exit.
   endif.

*4. Commit LUW
*   All successful, sent success message.

   clear: l_syst-msgid, l_syst-msgno.
   l_syst-msgty = 'S'.
   l_syst-msgv1 = 'Link created successfully'.

*  perform collect_message using ot_return l_syst '4. URLLinkCreated'.
*   append ot_return.
   if i_nocommit is initial.
     call function 'BAPI_TRANSACTION_COMMIT'.
   endif.

ENDFUNCTION.

C) Finally triggering the above two steps in a combination as soon as the Notification Task gets released.

Once everything is ready the only thing left is to find the place that should run the combination of above two steps as soon as the Notification Task gets release.

So for the same I found out that once you release the Task Released Event of Business Object QMSM gets trigger so I implemented the following steps after this:

  • Created a custom task in PFTC.
  • Added a new method in the extended business object of QMSM which I created as Z.
  • Attach the method inside the Task which includes our above mentioned code.
  • Now in the Task there is a Tab called triggering event where I have given the method Released of business object QMSM (so this make this Task only trigger for event Release of Business Object QMSM)
  • Once done activate the Task and here we go all set.
Rating: 0 / 5 (0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *